package com.lehecai.core.type.cooperator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lehecai.core.IntegerBeanLabelItem;

public class Cooperator extends IntegerBeanLabelItem {
	
	private static final long serialVersionUID = 3110108975234413739L;

	private static final Logger logger = LoggerFactory.getLogger(Cooperator.class.getName());

	private static List<Cooperator> _items = new ArrayList<Cooperator>();
	
	private static List<Cooperator> items;
	
	private static Map<String, Cooperator> nameMap = new HashMap<String, Cooperator>();

	protected Cooperator(String name, int value) {
		super(Cooperator.class.getName(), name, value);
		_items.add(this);
		
		nameMap.put(name, this);
	}
	
	public static Cooperator getItem(int value){
		try {
			return (Cooperator)Cooperator.getResult(Cooperator.class.getName(), value);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return null;
		}
	}
	
	public static Cooperator getItemByName(String name) {
		if (nameMap.containsKey(name)) {
			return nameMap.get(name);
		}
		return null;
	}
	
	public static List<Cooperator> getItems() {
		return items;
	}
	
	public final static Cooperator PLOT = new Cooperator("Plot", 1);
	
	public final static Cooperator HOOPCHINA = new Cooperator("HoopChina", 2);
	
	public final static Cooperator SOHU = new Cooperator("Sohu", 3);

    public final static Cooperator HAO123 = new Cooperator("Hao123", 4);
    
    public final static Cooperator BAIDU = new Cooperator("baidu", 5);
    
    public final static Cooperator SOTIPS = new Cooperator("sotips", 6);
	
	static {
		synchronized (_items) {
			items = Collections.unmodifiableList(_items);
		}
	}
}

